﻿using System;
using System.Globalization;
using System.Windows.Data;
using Tanmia.Warehouse.Core;

namespace Tanmia.Warehouse.Presentation.Scenarios
{
    public class DiscriminatorParentConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return Discriminator.HeadItem;
            else
                return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType == typeof(Discriminator))
                if (value.Equals(Discriminator.HeadItem))
                    return null;
                else
                    return value;

            return null;
        }
    }
}
